<template>
	<div class="popupadstyle">
		<h2>{{ datas.text }}</h2>
		<el-tabs type="border-card" :stretch="true">
			<el-tab-pane label="内容">
				<div class="decorate-card">
					<div class="title">展示图标</div>
					<el-form label-width="100px">
						<vuedraggable :list="datas.list" item-key="index" :forceFallback="true" :animation="200">
							<template #item="{ element, index }">
								<section class="imgBanner">
									<van-icon class="el-icon-circle-close" name="close" @click.stop="deleteInfo(index)" />
									<el-form-item label="广告图">
										<div class="sd-flex">
											<div class="choice-image choice-image-delete" @click="openFileChoiceDialog(index)">
												<el-image v-if="element.src != ''" :src="STATIC_URL + element.src" fit="cover" class="cover-image" />
												<el-icon v-else>
													<ele-Plus />
												</el-icon>

												<div class="delete-content" @click.stop="element.src = ''" v-if="element.src != ''">
													<SvgIcon name="ele-DeleteFilled"></SvgIcon>
												</div>
											</div>
										</div>
									</el-form-item>
									<el-form-item label="选择链接">
										<el-input v-model="element.url">
											<template #append> <el-button @click="openChoiceData(index)">选择</el-button> </template>
										</el-input>
									</el-form-item>

									<el-form-item label="显示次数">
										<el-radio-group v-model="element.show">
											<el-radio :label="1">仅显示一次</el-radio>
											<el-radio :label="2">首页显示</el-radio>
										</el-radio-group>
									</el-form-item>
								</section>
							</template>
						</vuedraggable>
						<!-- 添加导航按钮 -->
						<el-button @click="add" :icon="Plus"> 添加 </el-button>
					</el-form>
				</div>
			</el-tab-pane>

			<el-tab-pane label="数据">
				<StyleComponentData :datas="datas"></StyleComponentData>
			</el-tab-pane>
		</el-tabs>

		<FileChoice ref="FileChoiceRef" @choiceFile="choiceFile"></FileChoice>
		<PageData ref="PageDataRef" @choice="choicePage"></PageData>
	</div>
</template>

<script setup name="popupadstyle">
import vuedraggable from 'vuedraggable'; //拖拽组件
import { ref, defineAsyncComponent } from 'vue';
import { STATIC_URL } from '/@/utils/config';
import { Plus } from '@element-plus/icons-vue';
const FileChoice = defineAsyncComponent(() => import('/@/views/file/choice/index.vue'));
const FileChoiceRef = ref();

const PageData = defineAsyncComponent(() => import('/@/views/shop/data/page/choice/index.vue'));
const PageDataRef = ref();

const emits = defineEmits(['refreshScroll']);

const props = defineProps({
	datas: {},
});

const add = () => {
	props.datas.list.push({
		src: '',
		show: 1,
		url: '',
	});
};

const deleteInfo = (index) => {
	props.datas.list.splice(index, 1);
};

let choiceImageIndex = 0;
const choiceFile = (res) => {
	props.datas.list[choiceImageIndex].src = res[0].visitRelativePath;
	emits('refreshScroll');
};

const openFileChoiceDialog = (index) => {
	choiceImageIndex = index;
	FileChoiceRef.value.openFileChoiceDialog();
};

let choicePageIndex = 0;
const openChoiceData = (index) => {
	PageDataRef.value.openDialog();
	choicePageIndex = index;
};

const choicePage = (res) => {
	props.datas.list[choicePageIndex].url = res.urlContent;
};
</script>

<style lang="scss" scoped>
.popupadstyle {
	h2 {
		padding: 24px 16px 24px 0;
		margin-bottom: 15px;
		border-bottom: 1px solid #f2f4f6;
		font-size: 18px;
		font-weight: 600;
		color: #323233;
	}
}

.el-tabs--border-card {
	:deep(.el-tabs__content) {
		padding: 0px !important;
	}
	border: 0px;

	:deep(.el-tabs__header) {
		background-color: #d9d9d9 !important;
	}
}

.imgBanner {
	padding: 6px 12px;
	margin: 16px 7px;
	border-radius: 2px;
	background-color: #fff;
	box-shadow: 0 0 4px 0 rgba(10, 42, 97, 0.2);
	// display: flex;
	position: relative;
	cursor: pointer;

	&:hover {
		.el-icon-circle-close {
			display: block;
		}
	}
	/* 删除图标 */
	.el-icon-circle-close {
		position: absolute;
		right: -5px;
		top: -10px;
		cursor: pointer;
		font-size: 19px;
		display: none;
	}
}
</style>
